/* 
  该文件用于：管理整个项目的ajax请求，每一个后端接口，都在这文件中对应一个函数
  该文件中，所有的函数，命名规范都为：reqXxxxx
*/

// 引入前台项目接口的请求
import qtajax from "@/utils/qiantai";
// 引入分类页的数据
import cateajax from "@/utils/cateajax";
// 引入网易项目请求的接口
import ajax from "./ajax";
// 引入首页的数据
import homeAjax from "@/utils/home";

// 该函数专门用于：获取验证码
export const reqSendCode = (phone) =>
  qtajax.get(`/user/passport/sendCode/${phone}`);

// 该函数专门用于：请求注册(参数为对象，包含：phone,code,password属性)
export const reqRegister = (paramsObj) =>
  qtajax.post(`/user/passport/register`, paramsObj);

// 该函数专门用于：请求登录(参数为对象，包含：phone，password属性)
export const reqLogin = (paramsObj) =>
  qtajax.post("/user/passport/login", paramsObj);

// 该函数专门用于：根据token获取用户信息
export const reqUserInfo = () => qtajax.get("/user/passport/auth/getUserInfo");

// 该函数专门用于：退出登录
export const reqLogout = ()=> qtajax.get('/user/passport/logout')

//该函数专门用于：请求值得买页面轮播图数据
export const reqNavList = () => ajax.get('/v1/know/navWap.json')

//该函数专门用于：分类页‘为你推荐’和分类列表的数据
export const reqCateListNav = () => cateajax.get('/cateList.json?__timestamp=1630131286110&categoryId=')

//该函数专门用于：分类页根据分类ID获取分类的列表数据
export const reqCurrentCateList = (categoryId) => cateajax.get(`/cateList.json?__timestamp=1630131455012&categoryId=${categoryId}`)

//该函数专门用于：分类页获取某个分类下的商品列表数据
export const reqSubCateList = (subCategoryId, categoryId) => cateajax.get(`/list.json?__timestamp=1630133942864&categoryType=0&subCategoryId=${subCategoryId}&categoryId=${categoryId}`)
// export const reqSubCateList = () => cateajax.get('/list.json?__timestamp=1630133942864&categoryType=0&subCategoryId=1008009&categoryId=1005000')

//此函数专门用于获取首页推荐列表
export const reqRecommendInfo = (phone) =>
  homeAjax.get("/xhr/index.json?__timestamp=1630131808529");

//此函数专门用于获取首页导航及家居列表
export const reqCateList = (id, phone) =>
  homeAjax.get(`/item/list.json?timestamp=${phone}&categoryId=${id}`);
//此函数专门用于获取搜索默认关键字和热门关键字
export const reqSearchInfo = () => homeAjax.get("/xhr/search/init.json");

//该函数专门用于：获取商品详情，注意：此接口需要参数
export const reqGoodDetailInfo = (id) => qtajax.get('/item/'+id)

// 该函数专门用于：请求购物车数据
export const reqCartList = () => qtajax.get('/cart/cartList');

// 该函数专门用于：切换购物车中商品的选中状态
export const reqCheckOneCart = (id,isChecked) => qtajax.get(`/cart/checkCart/${id}/${isChecked}`)

// 该函数专门用于：全选购物车
export const reqCheckAllCart = (idList,isChecked) => qtajax.post(`/cart/batchCheckCart/${isChecked}`,idList)

// 该函数专门用于：删除购物车中的某个商品
export const reqDeleteOneCart = (id) => qtajax.delete(`/cart/deleteCart/${id}`)

// 该函数专门用于：批量删除购物车中的商品
export const reqBatchDeleteCart = (idList) => qtajax.post('/cart/batchDeleteCart',idList)

// 该函数专门用于：添加商品到购物车 也能修改购物车中商品数量（正数代表加，负数代表减）
export const reqAddGood2Cart = (goodId,goodNum) => qtajax.post(`/cart/addToCart/${goodId}/${goodNum}`)

// 该函数专门用于：获取支付信息
export const reqPayInfo = (orderId) => qtajax.get(`/payment/weixin/createNative/${orderId}`)
//给函数专门用于：获取瀑布流的数据
export const reqWaterfallList = (group) =>
  ajax.get(`/v1/find/recAuto.json?page=${group}&size=1`);

// 获取关键字的请求
export const reqSearchKeyWord = (keywordPrefix) =>
  homeAjax.post(
    `/xhr/search/searchAutoComplete.json`,
    "keywordPrefix=" + keywordPrefix,
    {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
      },
    }
  );
